<?php
App::uses('AppModel', 'Model');
/**
 * Slider Model
 *
 */
class Slider extends AppModel {
    
/**
 * Display field
 *
 * @var string
 */
    public $displayField = 'filename';
    
    /**
     * Validation rules
     *
     * @var array
     */
    public $validate = array(
        'filename' => array(
            array(
                'rule' => 'notEmpty',
                'message' => 'Ingrese un Titulo',
                'required' => true,
            ),
        ),    
        'type' => array(
            'rule'    => array('extension', array('gif', 'jpeg', 'png', 'jpg')),
            'message' => 'Seleccione una imagen válida',
            'allowEmpty' => true,
        )
    );

   public $actsAs = array(
        'Uploader.Attachment' => array(
            'filepath' => array(
                'name' => 'formatFileName', // Name of the function to use to format filenames
                'uploadDir' => 'uploads/slider/', // See UploaderComponent::$uploadDir
                'dbColumn' => 'filepath', // The database column name to save the path to
                'maxNameLength' => 50,
                'overwrite' => true, // Overwrite file with same name if it exists
                'stopSave' => true, // Stop the model save() if upload fails
                'allowEmpty' => true, // Allow an empty file upload to contin
                'metaColumns'   => array(       // Mapping of meta data to database fields
                    'ext' => 'type',
                    'width' => 'width',
                    'height' => 'height',
                )             
            )
        ),       
    );
    
    function formatFileName($name, $field, $file) {
        return md5($name);
    }

    public function beforeSave() {
        if (!empty($this->data)) {
        }
        return true;
    }
}
